import numpy as np

# 读取txt文件
with open('imu.txt', 'r') as f:
    lines = f.readlines()[1:] # 从第二行开始读取
    data = []
    for line in lines:
        cols = line.strip().split(' ')
        timestamp = cols[0]
        omega_x = np.deg2rad(float(cols[1]))
        omega_y = np.deg2rad(float(cols[2]))
        omega_z = np.deg2rad(float(cols[3]))
        alpha_x = float(cols[4])
        alpha_y = float(cols[5])
        alpha_z = float(cols[6])
        row = [timestamp, omega_x, omega_y, omega_z, alpha_x, alpha_y, alpha_z]
        data.append(row)

# 将数据保存到csv文件
with open('imu_rads.csv', 'w') as f:
    f.write('timestamp,omega_x,omega_y,omega_z,alpha_x,alpha_y,alpha_z\n')
    for row in data:
        f.write(','.join(str(x) for x in row) + '\n')